﻿/*
 * The MIT License
 *
 * Copyright (c) 2008 Raffaele Sena <raff367@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

import util.*;

class BarChart.Main
{
	private var parent:MovieClip;
	private var current:Number = 0;
	private var delta:Number = 7;
	private var bar:BarChart;
	
	function Main(mc:MovieClip)
	{
		// save reference to main movieclip
		this.parent = mc;
		
		// set background and app title
		UI.mainScreen(mc, UI.BLUE_1, "My First Chumby Application");
		
		// create bar chart
		bar = new BarChart(mc, 10, 40, 300, 190, 8, UI.BLACK, UI.CYAN);
		
		// start timer
		setInterval(this, "onTimer", 100);	
		
		mc.app = this;
		mc.onMouseDown = function() {
			this.app.bar.clear();
		}
	}
    
	function onTimer()
	{
		current += (delta - int(Math.random() * 10));
		if (current > 100) {
			current = 100;
			delta = 3;
		} else if (current < 0) {
			current = 0;
			delta = 7;
		}
		
		trace(current);
		bar.add(current);
	}
	
	static function main(mc:MovieClip)
	{
		var app = new Main(mc);
	}
}
